#!/bin/bash
# File Name   : clear.sh
# Author      : moshan
# Mail        : mo_shan@yeah.net
# Created Time: 2022-04-09 15:40:16
# Function    : 
#########################################################################

dev="${1}"

count="${2}"

size=$(df |grep "${dev}$"|awk '{print int($2/1024/1024/2)}')

cd ${dev} || exit

[ -z "${size}" ] && exit

function prepare_tmp_data()
{
    for ((i=0; i<=${size}; i++))
    do
        dd if=/dev/zero of=$(md5sum <<< "${i}"|awk '{print $1}').log bs=2G count=1 || break
    done

    used="$(df |grep "^${dev} "|awk '{print $5}')"

    if [ "${used}x" != "100%" ]
    then
        dd if=/dev/zero of=$(md5sum <<< "${i}"|awk '{print $1}').log bs=2G count=20
    fi
}

function f_main()
{
    for ((c=0; c<=${count}; c++))
    do
		prepare_tmp_data
    done
}

f_main
